package Test.SynchronousQueueDemo;

import java.util.concurrent.SynchronousQueue;

/**
 * @author pengshuai
 * @date 2022/1/27 22:59
 */
public class Demo05 {

    public static void main(String[] args) throws InterruptedException {


        SynchronousQueue<Integer> queue = new SynchronousQueue<>(true);

        Thread thread = new Thread(() -> {
            try {
                queue.put(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread.start();

        Thread.sleep(200);

        Thread thread1 = new Thread(() -> {
            try {
                queue.put(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread.start();

        Thread.sleep(200);
        thread1.interrupt();
        Thread.sleep(200);

        Thread thread2 = new Thread(() -> {
            try {
                queue.put(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread.start();

        Thread.sleep(200);
        thread2.interrupt();




    }

}
